/**
 * 授权 API
 */
import {
	http
} from '../request/main.js';

/**
 * 用户登录 - 姓名登录码
 * 
 * @returns {Promise}
 */
export function loginByNameCode(name, code, wx_code, auth_key) {
	return http.post('/user/loginByNameCode', {
		name,
		code,
		wx_code,
		auth_key
	}, {
		muteLogin: true
	})
}

/**
 * 用户登录 - 编号登录码
 * 
 * @returns {Promise}
 */
export function loginByNumberCode(number, code, wx_code, auth_key) {
	return http.post('/user/loginByNumberCode', {
		number,
		code,
		wx_code,
		auth_key
	}, {
		muteLogin: true
	})
}

/**
 * 用户登录 - 手机验证码
 * 
 * @returns {Promise}
 */
export function loginByPhoneCaptcha(phone, captcha, wx_code, auth_key) {
	return http.post('/user/loginByPhoneCaptcha', {
		phone,
		captcha,
		wx_code,
		auth_key
	}, {
		muteLogin: true
	})
}

/**
 * 用户登录 - 微信快捷登录
 * 
 * @returns {Promise}
 */
export function loginByWechatPhone(encrypted_data, iv, code, wx_code) {
	return http.post('/user/loginByWechatPhone', {
		encrypted_data,
		iv,
		code,
		wx_code
	}, {
		muteLogin: true
	})
}

/**
 * 小程序自动登录
 * 
 * @returns {Promise}
 */
export function wechatAutoLogin(wx_code) {
	return http.post('/user/wechatAutoLogin', {
		wx_code
	}, {
		muteLogin: true
	})
}

/**
 * 微信网页自动登录
 *
 * @returns {Promise}
 */
export function mpAutoLogin(auth_key) {
	return http.post('/user/mpAutoLogin', {
		auth_key
	}, {
		muteLogin: true
	})
}

/**
 * 发送手机验证吗
 * 
 * @returns {Promise}
 */
export function sendPhoneCaptcha(phone, wx_code, muteLogin) {
	return http.post('/user/sendPhoneCaptcha', {
		phone,
		wx_code
	}, {
		muteLogin: muteLogin
	})
}


/**
 * 用户登出
 * 
 * @returns {Promise}
 */
export function logout() {
	return http.post('/user/logout')
}

/**
 * 更新用户信息
 * 
 * @returns {Promise}
 */
export function updateUserInfo(avatar_url) {
	return http.post('/user/updateUserInfo', {
		avatar_url
	})
}

/**
 * 获取用户信息
 * 
 * @returns {Promise}
 */
export function getUserInfo() {
	return http.post('/user/getUserInfo')
}

/**
 * 修改登录码
 * 
 * @returns {Promise}
 */
export function changeCode(oldCode, newCode) {
	return http.post('/user/changeCode', {
		oldCode,
		newCode
	})
}

/**
 * 修改手机号
 * 
 * @returns {Promise}
 */
export function changePhone(phone, captcha) {
	return http.post('/user/changePhone', {
		phone,
		captcha
	})
}

/**
 * 修改手机号 - 授权微信手机号
 * 
 * @returns {Promise}
 */
export function changeWechatPhone(encrypted_data, iv, code, wx_code) {
	return http.post('/user/changeWechatPhone', {
		encrypted_data,
		iv,
		code,
		wx_code
	})
}

/**
 * 获取我的资产
 * 
 * @returns {Promise}
 */
export function getMineFund() {
	return http.post('/fund/getMineData');
}

/**
 * 获取资产记录
 * 
 * @returns {Promise}
 */
export function getFundRecord(page, page_size) {
	return http.post('/fund/getRecordList', {
		page,
		page_size
	});
}